home *** CD-ROM | disk | FTP | other *** search
- /* ====================
- * PedDataSourceFile.cc
- * ====================
- */
-
- #include <Files.h>
-
- #include <string.h>
-
- #include "PedDataSourceFile.hh"
- #include "PedFSRef.hh"
- #include "PedBuffer.hh"
- #include "PedAccess.hh"
-
-
- PedDataSourceFile::PedDataSourceFile(PedFSRef &inFSRef, short inFork)
- {
- PedAccessRaw *access = inFork
- ? (PedAccessRaw *) new PedAccessRF(inFSRef, fsRdPerm)
- : (PedAccessRaw *) new PedAccessData(inFSRef, fsRdPerm);
- mAccess = access;
- }
-
- PedDataSourceFile::~PedDataSourceFile()
- {
- if (mAccess) {
- mAccess->release();
- }
- }
-
- PedBuffer *
- PedDataSourceFile::GetNextBuffer()
- {
- if (!mAccess) return NULL;
-
- enum {kDefaultBufferSize = 512};
- long bytesRead;
- PedBuffer *buf;
- buf = new PedBuffer(kDefaultBufferSize);
- bytesRead = mAccess->Read(kDefaultBufferSize, buf->Ptr());
- if (bytesRead > 0) {
- buf->SetLength(bytesRead);
- buf->autorelease();
- return buf;
- } else {
- delete buf;
- return NULL;
- }
- }
-